package com.gxa.customer.mqconfig;

import com.gxa.common.pojo.Emailpojo;
import com.gxa.common.utils.EmailUtils;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


import java.io.IOException;
import java.util.Date;

@Slf4j
@Component
public class DeadLetterQueueConsumer {
    @RabbitListener(queues = "QDA")
    @RabbitHandler
    public void receiveDA(Emailpojo emailpojo)  {
        EmailUtils.sendMail(emailpojo.getSenderTo(),emailpojo.getSubject(),emailpojo.getText());
        log.info("当前时间：{},邮箱异步队列信息{}", new Date().toString(), emailpojo);
    }

    @RabbitListener(queues = "QDB")
    public void receiveDB(Message message, Channel channel) throws IOException {
        String msg = new String(message.getBody());
        log.info("当前时间：{},收到死信队列信息{}", new Date().toString(), msg);
    }
}